package com.bw.dubbo;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.ServiceConfig;
import com.bw.service.UserService;
import com.bw.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by qpx on 2018/6/21.
 */
@Configuration
public class dubboConfig {

    @Autowired
    UserService userService;


    @Bean
    public ServiceConfig config(){
        // Application Info
        ApplicationConfig application = new ApplicationConfig();
        application.setName("producer1");

                // Registry Info
        RegistryConfig registry = new RegistryConfig();
        registry.setAddress("zookeeper://127.0.0.1:2181");

        // Protocol
        ProtocolConfig protocol = new ProtocolConfig();
        protocol.setName("dubbo");
        protocol.setPort(20881);

        ServiceConfig<UserService> service = new ServiceConfig<UserService>(); // In case of memory leak, please cache.
        service.setApplication(application);
        service.setRegistry(registry); // Use setRegistries() for multi-registry case
        service.setProtocol(protocol); // Use setProtocols() for multi-protocol case
        service.setInterface(UserService.class);
        service.setRef(userService);
//        service.setVersion("1.0.0");
        // Local export and register
        service.export();
        return service;
    }


}
